package net.sf.midollo.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.midollo.net.cgitunnel.server.CGITunnelServerFactory;
import net.sf.midollo.net.httptunnel.server.HttpTunnelServer;
import net.sf.midollo.net.httptunnel.server.servlet.HttpTunnelServletHelper;

public class HT extends MyHttpServlet {

  private static final long serialVersionUID = 1L;

  private HttpTunnelServletHelper helper;

  public void init() throws ServletException {
    try {
      super.init();
      CGITunnelServerFactory protocolFactory = new CGITunnelServerFactory();
      HttpTunnelServer server = new HttpTunnelServer(protocolFactory);
      this.helper = new HttpTunnelServletHelper(server);
    } catch (IOException e) {
      throw new ServletException(e.toString());
    }
  }

  protected void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
    try {
      this.helper.dispatch(httpServletRequest, httpServletResponse);
    } catch (IOException e) {
      log("doPost", e);
      throw e;
    }
  }
}
